package com.tjsinfo.tjsoa.chuanyue.bo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.Dao.ISpringDao;
import com.tjsinfo.tjsoa.chuanyue.dao.ITChuanyueNeirongDAO;
import com.tjsinfo.tjsoa.chuanyue.vo.TChuanyueFujian;
import com.tjsinfo.tjsoa.chuanyue.vo.TChuanyueNeirong;
import com.tjsinfo.tjsoa.system.vo.Files;

public class TChuanyueNeirongBO implements ITChuanyueNeirongBO {
	private ITChuanyueNeirongDAO neirongDAO;
	private IQbcDao qbcDao;
	private ISpringDao springDao;
	
	
	
	public ISpringDao getSpringDao() {
		return springDao;
	}
	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}
	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public ITChuanyueNeirongDAO getNeirongDAO() {
		return neirongDAO;
	}

	public void setNeirongDAO(ITChuanyueNeirongDAO neirongDAO) {
		this.neirongDAO = neirongDAO;
	}

	public String addValue(TChuanyueNeirong neirong, List<Files> list) {
		// TODO Auto-generated method stub
		
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			Files file = (Files) iterator.next();
			TChuanyueFujian fujian = new TChuanyueFujian();
			fujian.setFujianAddress(file.toFilePath);
			fujian.setFujianName(file.getOldFileName());
			fujian.setFujianZhengname(file.getNewFileName());
			neirong.addFuJian(fujian);
		}
		return neirongDAO.save(neirong);
	}

	public List<TChuanyueNeirong> findByExample(TChuanyueNeirong neirong) {
		// TODO Auto-generated method stub
		return neirongDAO.findByExample(neirong);
	}

	public TChuanyueNeirong selectById(String id) {
		// TODO Auto-generated method stub
		TChuanyueNeirong neirong = neirongDAO.findById(id);
		return neirong;
	}

	public List<TChuanyueNeirong> selectPage(Integer firest, Integer max) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TChuanyueNeirong.class);
		List<Order> orderlist = new ArrayList<Order>();
		orderlist.add(Order.desc("sortid"));
		return qbcDao.findPageByCriteria(criteria,orderlist, max, firest).getItems();
	}

	public List<TChuanyueNeirong> selectTChuanyueNeirongPage(
			DetachedCriteria criteria, Integer firest, Integer max) {
		// TODO Auto-generated method stub
		List<Order> orderlist = new ArrayList<Order>();
		orderlist.add(Order.desc("sortid"));
		return qbcDao.findPageByCriteria(criteria,orderlist, max, firest).getItems();
	}

	public Integer seletPageTotalLine() {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TChuanyueNeirong.class);
		return qbcDao.getQueryNumber(criteria, "id");
	}

	public Integer seletTTongyongxingzhengshengpiPageTotalLine(
			DetachedCriteria criteria) {
		// TODO Auto-generated method stub
		return qbcDao.getQueryNumber(criteria, "id");
	}

	public Boolean updateValue(TChuanyueNeirong neirong) {
		// TODO Auto-generated method stub
		 try {
				neirongDAO.merge(neirong);
				 return true;
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			}
	}

	public Boolean deleteTask(Integer taskId){
		try {
			StringBuffer sql = new StringBuffer("delete from  dbo.JBPM_LOG WHERE TASKINSTANCE_ = ?  ");
			springDao.commonUpdate(sql.toString(), new Object[]{taskId});
			 sql = new StringBuffer("delete from JBPM_TASKINSTANCE where ID_ = ? ");
			springDao.commonUpdate(sql.toString(), new Object[]{taskId});
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}
}
